package app.sceledroid.network;

import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import app.sceledroid.entity.Course;
import app.sceledroid.entity.Forum;
import app.sceledroid.entity.GrabberEntity;
import app.sceledroid.entity.Deadline;
import app.sceledroid.entity.Resource;
import app.sceledroid.services.SceleService;

public class ResourceGrabber extends AsyncTask<Document, Integer, ArrayList<Resource>> {

	private Context context;
	private HttpClient client;
	private Course course;
	
	public ResourceGrabber(Course course, Context context, HttpClient client) {
		super();
		this.context = context;
		this.course = course;
		this.client = client;
	}
	
	@Override
	protected ArrayList<Resource> doInBackground(Document... params) {
		
		//DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy, KK:mm a");
		ArrayList<Resource> resources = new ArrayList<Resource>();
		course.setResources(resources);
		Document doc = params[0];
		Elements elements = doc.select("li.resource a");
		for (Element el : elements) {
			
				String href = el.attr("href");
				Element e = el.select(".accesshide").first();
				
				String rName = el.text();
				Resource resource = new Resource(rName, href);
if(e.text().contains("Powerpoint")) {
					
					
				}else if(e.text().contains("zip"))
				{
				
				}
				else if(e.text().contains("PDF")) {
					
					
				}
				else if(e.text().contains("Word")) {
					
					
				}
				else if(e.text().contains("Excel")) {
					
					
				}
				Log.v("RESOURCE", rName);
				resources.add(resource);
		}

		return course.getResources();
	}

}
